//
//  WH_OrderDetailVC.m
//  App_6.23
//
//  Created by wanghao on 16/7/19.
//  Copyright © 2016年 wanghao. All rights reserved.
//

#import "WH_OrderDetailVC.h"
#import "WH_Home.h"
@interface WH_OrderDetailVC ()

@property (nonatomic, strong) UILabel *allnum;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, assign) CGFloat labelY;

@end

@implementation WH_OrderDetailVC

-(void)viewWillAppear:(BOOL)animated{
    
    
    [self.tabBarController.tabBar setHidden:YES];
}
-(void)viewWillDisappear:(BOOL)animated{
    
    
    [self.tabBarController.tabBar setHidden:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"夺宝号码";
    //UIScrollView 是所有滚动视图的基类
    self.scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.view addSubview:self.scrollView];
    //取消边界反弹效果
    self.scrollView.bounces = NO;
    [self createView];
    [self postData];
}

-(void)postData{
    
    NSString *body = [NSString stringWithFormat:@"action=order_code&user_id=%@&order_id=%@&product_period=%@",self.orderModel.userid, self.orderModel.order_id, self.orderModel.product_period];
    NSLog(@"product_period==%@",_orderModel.product_period);
    [WH_AppTools postUrl:URLstr body:body result:HXJSON requestStyle:HXRequestString headerFile:nil success:^(id result) {
        
        NSLog(@"%@",result);
        NSDictionary *dic = result;
        
        NSString *orderStr = [dic objectForKey:@"code"];
        NSString *strUrl = [orderStr stringByReplacingOccurrencesOfString:@"," withString:@"  "];
        CGSize labelS = [WH_AppTools labelRectWithSize:CGSizeMake(SCREEN_WIDTH, 11110) LabelText:strUrl Font:[UIFont systemFontOfSize:14.f]];
        _allnum.frame = CGRectMake(10, _labelY, SCREEN_WIDTH, labelS.height);
        
        _allnum.text = [NSString stringWithFormat:@"%@",strUrl];
        self.scrollView.contentSize = CGSizeMake(SCREEN_WIDTH, labelS.height + 145);
        NSLog(@"height=====%f",labelS.height);
    } failure:^(NSError *error) {
        
        
    }];
}

-(void)createView{
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 125)];
    view.backgroundColor = [UIColor colorWithRed:0.97 green:0.97 blue:0.97 alpha:1];
    [self.scrollView addSubview:view];
    
    UILabel *nameL = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH - 10*2, 60)];
    nameL.text = self.orderModel.product_name;
    nameL.numberOfLines = 2;
    [nameL sizeToFit];
    nameL.font = [UIFont boldSystemFontOfSize:17.f];
    [view addSubview:nameL];
    
    UILabel *periodL = [[UILabel alloc] initWithFrame:CGRectMake(nameL.frame.origin.x, nameL.frame.origin.y + nameL.frame.size.height + 10, nameL.frame.size.width, 20)];
    periodL.text = [NSString stringWithFormat:@"期号:  %@",self.orderModel.product_period_no];
    periodL.font = [UIFont systemFontOfSize:14.f];
    [view addSubview:periodL];

    UILabel *winNumL = [[UILabel alloc] initWithFrame:CGRectMake(periodL.frame.origin.x, periodL.frame.origin.y + periodL.frame.size.height + 10, periodL.frame.size.width, periodL.frame.size.height)];
    if ([self.orderModel.win_num isEqualToString:@"0"]) {
        
        winNumL.text = [NSString stringWithFormat:@"本期幸运号码: Loading..."];

    }else{
        
        
        winNumL.text = [NSString stringWithFormat:@"本期幸运号码: %@",self.orderModel.win_num];
    }
    winNumL.font = [UIFont systemFontOfSize:14.f];
    [view addSubview:winNumL];
    [WH_AppTools changeColor:winNumL.text color:[UIColor redColor] xx:self.orderModel.win_num nn:winNumL];
    
    UILabel *countL = [[UILabel alloc] initWithFrame:CGRectMake(0, view.frame.size.height + 5, SCREEN_WIDTH, 20)];
    countL.text = [NSString stringWithFormat:@"参与了%@人次,以下是所有夺宝号码",self.orderModel.order_num];
    countL.textAlignment = NSTextAlignmentCenter;
    countL.font = [UIFont systemFontOfSize:14.f];
    
    [WH_AppTools changeColor:countL.text color:[UIColor redColor] xx:self.orderModel.order_num nn:countL];
    [self.scrollView addSubview:countL];
    
    UILabel *aLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, countL.frame.size.height + countL.frame.origin.y + 5, SCREEN_WIDTH, 1)];
    aLabel.backgroundColor = [UIColor colorWithRed:0.86 green:0.85 blue:0.86 alpha:1];
    [self.scrollView addSubview:aLabel];
    
    self.allnum = [UILabel new];
    _allnum.font = [UIFont systemFontOfSize:14.f];
    _labelY = aLabel.frame.origin.y + 5;
    _allnum.numberOfLines = 0;
    [self.scrollView addSubview:_allnum];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
